#ifndef __GAME_DEGUE_H__
#define __GAME_DEGUE_H__

#include "stdio.h"
#include <string>
//#include "../System/System.h"
#define _GM_DEGUG_

#define C_USE_DEBUG 
//#define C_USE_LOG_DEBUG 
#define C_AUTHOR_NAME "xhb"

#ifdef _C_SYS_HISIANDROID
       #include <android/log.h>
               
       #define printf(...)                                __android_log_print(ANDROID_LOG_INFO, "[gm]", __VA_ARGS__)
#else
       //#define printf(...)                                printf(__VA_ARGS__);
#endif

#ifdef WIN32
#define ProjectName "source"
#define ProjectName_len (6)
char * _GetFileName(char *) ;
#endif


#ifdef _GM_DEGUG_
#define Gm_While(a)  while(a){ Sleep(1); }  
#else
#define Gm_While(a)
#endif

#define GM_NOT_USED(x) 	((void)(x))

#ifdef C_USE_DEBUG

#ifdef C_USE_LOG_DEBUG
#define LogPrintf(fmt, ...) {printf(fmt,##__VA_ARGS__);fprintf(g_LogStream,fmt,##__VA_ARGS__);}
#ifdef gm_printf 
		#undef gm_printf
		#define gm_printf LogPrintf
#else
		#define gm_printf LogPrintf
#endif
#define Gm_Assert(a,s) \
		if(!(a)){ printf("Game == %s, %d, %s  \n", s, __LINE__, __FILE__); \
		fprintf(g_LogStream,"Game == %s, %d, %s  \n", s, __LINE__, __FILE__);Gm_While(1); }
#define PrintfString(fmt, ...)  \
		{printf(#fmt"==%s, :%s, :%d, ===\n", ##__VA_ARGS__, _GetFileName(__FILE__), __FUNCTION__, __LINE__); \
		fprintf(g_LogStream,#fmt"==%s, :%s, :%d, ===\n", ##__VA_ARGS__, _GetFileName(__FILE__), __FUNCTION__, __LINE__);}
#define GmPrint(fmt, ...) \
		{ printf("---GmPrint---"#fmt"==%s, :%s, :%d, ===\n", \
		##__VA_ARGS__, __FILE__ , __FUNCTION__, __LINE__);\
		fprintf(g_LogStream,"---GmPrint---"#fmt"==Game :%s, :%s, :%d, ===\n", \
		##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__); }
#define GmPrintfString(fmt, ...) \
		{ printf("---GmPrintfString---"#fmt"==%s, :%s, :%d, ===\n", \
		##__VA_ARGS__, __FILE__ , __FUNCTION__, __LINE__);\
		fprintf(g_LogStream,"---GmPrintfString---"#fmt"==Game :%s, :%s, :%d, ===\n", \
		##__VA_ARGS__, __FILE__ , __FUNCTION__, __LINE__); }
#define WhereIs(dwID, tabName) \
		static DWORD sdwRecID = 0xffffffff; \
		if(sdwRecID != dwID)\
		{	printf("====%s, %d, %d,Now is %s \n", __FUNCTION__, __LINE__, dwID, tabName[dwID] );\
			fprintf(g_LogStream,"====%s, %d, %d,Now is %s \n", __FUNCTION__, __LINE__, dwID, tabName[dwID] );\
			sdwRecID = dwID;\
		}
		
#define LogDebug(fmt, ...)  \
		{ printf("---"C_AUTHOR_NAME" debug---"#fmt"==%s, :%s, :%d, ===\n", \
		##__VA_ARGS__, _GetFileName(__FILE__), __FUNCTION__, __LINE__);\
		fprintf(g_LogStream,"---"C_AUTHOR_NAME" debug---"#fmt"==%s, :%s, :%d, ===\n", \
		##__VA_ARGS__, _GetFileName(__FILE__), __FUNCTION__, __LINE__); }
#define LogEnter  \
		{ printf("---"C_AUTHOR_NAME" Info---Enter  ==%s, :%s, :%d, ===\n",_GetFileName(__FILE__), __FUNCTION__, __LINE__); \
		fprintf(g_LogStream,"---"C_AUTHOR_NAME" Info---Enter  ==%s, :%s, :%d, ===\n", _GetFileName(__FILE__), __FUNCTION__, __LINE__); }
#define LogInfo(fmt, ...)  \
		{ printf("---"C_AUTHOR_NAME" Info---"#fmt"\n",##__VA_ARGS__);\
		fprintf(g_LogStream,"---"C_AUTHOR_NAME" Info---"#fmt"\n",##__VA_ARGS__); }
#define LogErr(fmt, ...)  \
		{ printf("[%s]---"C_AUTHOR_NAME" Error---"#fmt"==Game :%s, :%s, :%d, ===\n", \
		__TIME__,##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__);\
		fprintf(g_LogStream,"[%s]---"C_AUTHOR_NAME" Error---"#fmt"==Game :%s, :%s, :%d, ===\n", \
		__TIME__,##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__); }
#define LogLocation(x,y)  \
		{ printf("---"C_AUTHOR_NAME" debug---x=%d,y=%d==%s, :%s, :%d, ===\n",\
		x,y, _GetFileName(__FILE__), __FUNCTION__, __LINE__);\
		fprintf(g_LogStream,"---"C_AUTHOR_NAME" debug---x=%d,y=%d==%s, :%s, :%d, ===\n",\
		x,y, _GetFileName(__FILE__), __FUNCTION__, __LINE__);}
#define printLine(fmt,...) {printf(#fmt"\n",##__VA_ARGS__);\
						fprintf(g_LogStream,#fmt"\n",##__VA_ARGS__);}

#define PrintPt(pt)  \
		{ printf("---"C_AUTHOR_NAME" debug---x=%d,y=%d==%s, :%s, :%d, ===\n",\
		pt.x,pt.y, _GetFileName(__FILE__), __FUNCTION__, __LINE__);\
		fprintf(g_LogStream,"---"C_AUTHOR_NAME" debug---x=%d,y=%d==%s, :%s, :%d, ===\n",\
		pt.x,pt.y, _GetFileName(__FILE__), __FUNCTION__, __LINE__);}
#define PrintLPt(pt)  \
		{ printf("---"C_AUTHOR_NAME" debug---x=%d,y=%d==%s, :%s, :%d, ===\n",\
		pt.lx,pt.ly, _GetFileName(__FILE__), __FUNCTION__, __LINE__);\
		fprintf(g_LogStream,"---"C_AUTHOR_NAME" debug---x=%d,y=%d==%s, :%s, :%d, ===\n",\
		pt.lx,pt.ly, _GetFileName(__FILE__), __FUNCTION__, __LINE__);}
#define PrintRect(rect)  \
		{ printf("---"C_AUTHOR_NAME" debug---left=%d,top=%d,right=%d,bottom=%d==%s, :%s, :%d, ===\n",\
		rect.left,rect.top,rect.right,rect.bottom, _GetFileName(__FILE__), __FUNCTION__, __LINE__); \
		fprintf(g_LogStream,"---"C_AUTHOR_NAME" debug---left=%d,top=%d,right=%d,bottom=%d==%s, :%s, :%d, ===\n",\
		rect.left,rect.top,rect.right,rect.bottom, _GetFileName(__FILE__), __FUNCTION__, __LINE__); \
		}
#define Waitkey()  \
		{	printLine("====waitkey==== , %s, %d, %s ",__FUNCTION__, __LINE__, __FILE__);\
			FlushScreen(g_hWnd, GM_FPLF_PHY_BG_LAY1|GM_FPLF_PHY_BG_LAY2);\
			while(1)\
			{	if((GetGameKeyHigh()||RF_GetKeyHigh(RF_ID_EXT_MASTER)||RF_GetKeyHigh(RF_ID_EXT_SLAVE)) )\
				{break;}\
			}\
		}
#define INTERRUPT {printLine("==="C_AUTHOR_NAME"-INTERRUPT===");Waitkey();}

#else
#define LogPrintf(fmt, ...) {printf(fmt,##__VA_ARGS__);}
#define Gm_Assert(a,s) \
		if(!(a)){ printf("Game == %s, %d, %s  \n", s, __LINE__, __FILE__); Gm_While(1); }
#define PrintfString(fmt, ...)  \
		{ printf(#fmt"==Game :%s, :%s, :%d, ===\n", ##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__); }
#define GmPrint(fmt, ...) \
		printf("Game=== "#fmt"\n", ##__VA_ARGS__);

#define GmPrintfString(fmt, ...) \
		{ 	printf("//================== \n Game === "); \
		  	printf(fmt, ##__VA_ARGS__);  \
		   	printf(" :%s, :%d, ===\n",  __FUNCTION__, __LINE__); \
		   	printf("=====================//\n ");}
#define WhereIs(dwID, tabName) \
		static DWORD sdwRecID = 0xffffffff; \
		if(sdwRecID != dwID)\
		{	printf("====%s, %d, %d,Now is %s \n", __FUNCTION__, __LINE__, dwID, tabName[dwID] );\
			sdwRecID = dwID;\
		}

#define LogDebug(fmt, ...)  \
		{ printf("---"C_AUTHOR_NAME" debug---"#fmt"==Game :%s, :%s, :%d, ===\n", \
		##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__); }
#define LogEnter  \
		{ printf("---"C_AUTHOR_NAME" Info---Enter  ==Game :%s, :%s, :%d, ===\n", __FILE__, __FUNCTION__, __LINE__); }
#define LogInfo(fmt, ...)  \
		{ printf("---"C_AUTHOR_NAME" Info---"#fmt"---End Info---\n", ##__VA_ARGS__);}
#define LogErr(fmt, ...)  \
		{ printf("---"C_AUTHOR_NAME" Error---"#fmt"==Game :%s, :%s, :%d, ===\n",\
		##__VA_ARGS__, __FILE__, __FUNCTION__, __LINE__); }
#define LogLocation(x,y)  \
		{ printf("---"C_AUTHOR_NAME" debug---x=%d,y=%d==Game :%s, :%s, :%d, ===\n",\
		x,y, __FILE__, __FUNCTION__, __LINE__); }
#define printLine(fmt,...) {printf(#fmt"\n",##__VA_ARGS__);}

#define PrintPt(pt)  \
		{ printf("---"C_AUTHOR_NAME" debug---x=%d,y=%d==Game :%s, :%s, :%d, ===\n",\
		pt.x,pt.y, __FILE__, __FUNCTION__, __LINE__); }
#define PrintLPt(pt)  \
		{ printf("---"C_AUTHOR_NAME" debug---x=%d,y=%d==Game :%s, :%s, :%d, ===\n",\
		pt.lx,pt.ly, __FILE__, __FUNCTION__, __LINE__); }
#define PrintRect(rect)  \
		{ printf("---"C_AUTHOR_NAME" debug---left=%d,top=%d,right=%d,bottom=%d==Game :%s, :%s, :%d, ===\n",\
		rect.left,rect.top,rect.right,rect.bottom, __FILE__, __FUNCTION__, __LINE__); }
#define Waitkey()  \
		{	printf("====waitkey==== , %s, %d, %s \n",__FUNCTION__, __LINE__, __FILE__);\
			FlushScreen(g_hWnd, GM_FPLF_PHY_BG_LAY1|GM_FPLF_PHY_BG_LAY2);\
			while(1)\
			{	if((GetGameKeyHigh()||RF_GetKeyHigh(RF_ID_EXT_MASTER)||RF_GetKeyHigh(RF_ID_EXT_SLAVE)) )\
				{break;}\
			}\
		}
#define INTERRUPT {printf("==="C_AUTHOR_NAME"-INTERRUPT===\n");Waitkey();}

#endif
#else
#define LogPrintf(fmt, ...) {}
#define Waitkey()  {}
#define INTERRUPT {}
#define Gm_Assert(a,s) if(!(a)){ printf("Game == %s, %d, %s  \n", s, __LINE__, __FILE__); Gm_While(1); }
#define PrintfString(fmt, ...)  { }
#define GmPrint(fmt, ...) printf("Game=== "); printf(fmt, ##__VA_ARGS__);
#define GmPrintfString(fmt, ...) {}
#define WhereIs(dwID, tabName) \
		static DWORD sdwRecID = 0xffffffff; \
		if(sdwRecID != dwID)\
		{	printf("====%s, %d, %d,Now is %s \n", __FUNCTION__, __LINE__, dwID, tabName[dwID] );\
			sdwRecID = dwID;\
		}
#define LogDebug(fmt, ...)  {}
#define LogEnter  {}
#define LogInfo(fmt, ...) {}
#define LogErr(fmt, ...)  {}
#define LogLocation(x,y)  {}
#define printLine(fmt,...) {}
#define PrintPt(pt)  {}
#define PrintLPt(pt)  {}
#define PrintRect(rect)  {}
#endif


void InitLog(char * fileName);
void ExitLog();
extern FILE *g_LogStream;  
#endif

